package com.ruoyi.hotel.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.HlPost;
import com.ruoyi.hotel.service.IHlPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 岗位Controller
 * 
 * @author ruoyi
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/hotel/hlpost")
public class HlPostController extends BaseController
{
    @Autowired
    private IHlPostService hlPostService;

    /**
     * 查询岗位列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlpost:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlPost hlPost)
    {
        startPage();
        List<HlPost> list = hlPostService.selectHlPostList(hlPost);
        return getDataTable(list);
    }

    /**
     * 导出岗位列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlpost:export')")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlPost hlPost)
    {
        List<HlPost> list = hlPostService.selectHlPostList(hlPost);
        ExcelUtil<HlPost> util = new ExcelUtil<HlPost>(HlPost.class);
        util.exportExcel(response, list, "岗位数据");
    }

    /**
     * 获取岗位详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlpost:query')")
    @GetMapping(value = "/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") Long postId)
    {
        return success(hlPostService.selectHlPostById(postId));
    }
    

    /**
     * 修改岗位
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlpost:edit')")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlPost hlPost)
    {
        return toAjax(hlPostService.updateHlPost(hlPost));
    }

}
